package org.example.Aop;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.example.model.Sysrole;
import org.springframework.stereotype.Component;

import java.util.Arrays;
import java.util.List;


@Component
@Aspect
public class bilsAop {
    //用于记录缓存
    private static List<Sysrole> sysrolesList = Arrays.asList();
    public static int number = 0;

    @Pointcut("execution(* org.example.service.ResourcesService.*(..))")
    private void sysroleptx() {
    }

    @Around("bilsAop.sysroleptx()")
    public List<Sysrole> methods(ProceedingJoinPoint pjt) throws Throwable {
        if (number == 0) {
            List<Sysrole> ret = (List<Sysrole>) pjt.proceed();
            sysrolesList = ret;
            number++;
            return ret;
        } else {
            return (List<Sysrole>) pjt.proceed();
        }
    }

}
